package com.study.samsung.Dao;

import com.study.samsung.Entity.Commodityimg;
import com.study.samsung.Utils.RowMapper;
import com.study.samsung.Utils.SQLHelper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class CommodityimgDao {
    SQLHelper helper = new SQLHelper();
    public List<Commodityimg> selectAll(){
        String sql = "select * from commodityimg";
        return helper.query(sql,new CommodityimgRowmapper());
    }

    public List<Commodityimg> selectByid(Integer sid){
        String sql = "select tid from commodityimg where classify = ?";
        return  helper.query(sql, new RowMapper<Commodityimg>() {
            @Override
            public Commodityimg map(ResultSet rs) throws SQLException {
                Commodityimg ci = new Commodityimg();
                ci.setTid(rs.getInt("tid"));
                return ci;
            }
        },sid);
    }

    public Integer updateurl(Integer tid,String url){
        String sql = "update commodityimg set tname = ? where tid = ?";
        return  helper.update(sql,url,tid);
    }

    class CommodityimgRowmapper implements RowMapper<Commodityimg>{

        @Override
        public Commodityimg map(ResultSet rs) throws SQLException {
            return new Commodityimg(rs.getInt("tid"),
                    rs.getString("tname"),
                    rs.getInt("sid"),
                    rs.getInt("classify"));
        }
    }
}
